package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.entity.AcceptanceRecords;
import com.project.dto.InspectionQueryDTO;
import com.project.vo.AcceptancePageVO;
import com.project.vo.AcceptanceVO;
import com.project.vo.InspectionSummaryVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.project.vo.AcceptanceItemsVO;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface AcceptanceMapper extends BaseMapper<AcceptanceRecords> {

    /**
     * 根据ID获取验收记录详情
     * @param id 验收记录ID
     * @return 验收记录详情
     */
    AcceptanceVO getById(Long id);

    /**
     * 获取验收明细
     * @param id
     * @return
     */


    /**
     * 根据用户id获取用户名称
     * @param inspectorId
     * @return
     */
    @Select("select real_name from users where user_id = #{inspectorId}")
    String getByUserId(Integer inspectorId);


    /**
     * 根据验收记录id获取验收明细
     * @param id
     * @return
     */
    List<AcceptanceItemsVO> getItems(Long id);

    List<AcceptancePageVO> listall(InspectionQueryDTO inspectionQueryDTO);

    @Select("select * from acceptance_records where acceptance_no = #{acceptanceNo}")
    AcceptanceRecords getByAccId(String acceptanceNo);

    InspectionSummaryVO getInspectionStatistics(@Param("startDate") LocalDate start, @Param("endDate") LocalDate end);

    @Update("update acceptance_records set status = #{status} where acceptance_id = #{id}")
    void updateStatus(@Param("id") Long id,@Param("status") Integer status);

}